﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class ChiTietTraHangNCCDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertCTTHNCC(ChiTietTraHangNCCDTO ChiTietTraHangNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaMH", ChiTietTraHangNCC.MaMH);
            par[1] = new SqlParameter("@MaTHNCC", ChiTietTraHangNCC.MaTHNCC);
            par[2] = new SqlParameter("@SoLuong", ChiTietTraHangNCC.SoLuong);
            par[3] = new SqlParameter("@DonGia", ChiTietTraHangNCC.DonGia);
            par[4] = new SqlParameter("@ChietKhau", ChiTietTraHangNCC.ChietKhau);
            par[5] = new SqlParameter("@ThanhTien", ChiTietTraHangNCC.ThanhTien);
            try
            {
                helper.InsertQuery("sp_Insert_ChiTietTraHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateCTTHNCC(ChiTietTraHangNCCDTO ChiTietTraHangNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[6];
            par[0] = new SqlParameter("@MaMH", ChiTietTraHangNCC.MaMH);
            par[1] = new SqlParameter("@MaTHNCC", ChiTietTraHangNCC.MaTHNCC);
            par[2] = new SqlParameter("@SoLuong", ChiTietTraHangNCC.SoLuong);
            par[3] = new SqlParameter("@DonGia", ChiTietTraHangNCC.DonGia);
            par[4] = new SqlParameter("@ChietKhau", ChiTietTraHangNCC.ChietKhau);
            par[5] = new SqlParameter("@ThanhTien", ChiTietTraHangNCC.ThanhTien);
            try
            {
                helper.UpdateQuery("sp_Update_ChiTietTraHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteCTTHNCC(string MaMH, string MaTHNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[2];
            par[0] = new SqlParameter("@MaMH", MaMH);
            par[0] = new SqlParameter("@MaCTTHNCC", MaTHNCC);
            try
            {
                helper.DeleteQuery("sp_Delete_ChiTietTraHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_CTTHNCC()
        {
            helper = new Helper();
            DataSet ds_CTTHNCC = helper.SelectQuery("sp_LayDS_ChiTietTraHangNCC");
            return ds_CTTHNCC;
        }
        #endregion
    }
}